/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import entity.Ppm;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import library.KoneksiDB;

/**
 *
 * @author user
 */
public class DaftarPpm {
    
    Ppm ppm;
    
    //method untuk menambah pengajuan ppm
    public boolean tambahDataPPM(Ppm ppm){
        boolean hasil = false;
        this.ppm = ppm;
        KoneksiDB dbConn = new KoneksiDB();
        String sql = "insert into kegiatan_kerjasama(JUDUL_PPM, TANGGAL_PENGAJUAN_PPM, BESAR_DANA_DIAJUKAN, ID_SUMBER_BIAYA, "
                + "ID_BIDANG_PENELITIAN, LAMPIRAN_PROPOSAL_PPM, KETERANGAN_PPM, ID_JENIS_PPM, MITRA_PPM, "
                + "DESKRIPSI_MITRA_PPM, PERIHAL_KERJASAMA_MITRA, NO_SK_KERJASAMA_MITRA) "
                + "value('"+this.ppm.getJudulPpm()+
                "','"+this.ppm.getTanggalPengajuanPpm()+
                "','"+this.ppm.getBesarDanaDiajukan()+
                "','"+this.ppm.getSumberBiayaPpm().getIdSumberBiayaPpm()+
                "','"+this.ppm.getBidangPenelitian().getBidangPenelitian()+
                "','"+this.ppm.getLampiranProposalPpm()+
                "','"+this.ppm.getKeteranganPpm()+
                "','"+this.ppm.getJenisPpm().getIdJenisPpm()+
                "','"+this.ppm.getMitraPpm()+
                "','"+this.ppm.getDeskripsiMitraPpm()+
                "','"+this.ppm.getPerihalKerjaSamaMitra()+
                "','"+this.ppm.getNoSkKerjasamaMitra()+
                "')";
        PreparedStatement st;
        try {
            Connection conn = dbConn.getConnection();
            st = conn.prepareStatement(sql);
            int rs = st.executeUpdate(sql);
            if(rs > 0){
                hasil = true;
            } else{
                return false;
            }
        } catch (SQLException ex) {
            Logger.getLogger(DaftarKerjaSama.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            dbConn.closeConnection();
        }
        return hasil;
    }
    
}
